#include <stdio.h>

struct Edge
{
    int x, y;
    int cost;
};

int e, sum, n, point[ 110 ];
Edge edge[ 20000 ];

int Kruscal_F( int point[], int v )
{
    int i = v;
    if ( point[ i ] < 0 ) return i;
    while ( point[ i ] >= 0 )
        i = point[ i ];
    return point[ v ] = i;
}

void Kruscal( )
{
    int i, j, k, tmp, v1, v2;
    for ( i = 0; i < e; i++ )
    {
        k = i;
        for ( j = i + 1; j < e; j++ )
            if ( edge[ k ].cost > edge[ j ].cost )
                k = j;
        tmp = edge[ k ].x; edge[ k ].x = edge[ i ].x; edge[ i ].x = tmp;
        tmp = edge[ k ].y; edge[ k ].y = edge[ i ].y; edge[ i ].y = tmp;
        tmp = edge[ k ].cost; edge[ k ].cost = edge[ i ].cost; edge[ i ].cost = tmp;
    }
    for ( i = 1; i <= n; i++ )
        point[ i ] = -1;
    sum = i = j = 0;
    while ( j < n && i < e )
    {
        v1 = Kruscal_F( point, edge[ i ].x );
        v2 = Kruscal_F( point, edge[ i ].y );
        if ( v1 != v2 )
        {
            sum += edge[ i ].cost;
            point[ v1 ] = v2;
            j++;
        }
        i++;
    }
}

int main( )
{
    while ( scanf("%d", &n) != EOF && n)
    {
        int i, t, a, b;
        e = 0;
        for ( i = 0; i < n * ( n - 1 ) / 2; i++ )
        {
            scanf("%d%d%d", &a, &b, &t);
            edge[ e ].x = a;
            edge[ e ].y = b;
            edge[ e ].cost = t;
            e++;
        }
        Kruscal( );
        printf("%d\n", sum);
    }
    return 0;
}

